package com.example.rubbish.Ui;

import android.content.Context;
import android.content.res.TypedArray;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.Nullable;

import com.example.rubbish.R;

public class NumberTextView extends LinearLayout {
    private String mNumber;
    private String mText;
    private int mTextSize;
    private int mMaxLine;
   public TextView number;
   public TextView textView;



    public void setTextView(String text) {
        mText = text;
        textView.setText(mText);
        requestLayout();
        invalidate();

    }

    public NumberTextView(Context context) {

        super(context);
    }

    public NumberTextView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        TypedArray ta =context.obtainStyledAttributes(attrs, R.styleable.NumberTextView);
        mNumber=ta.getString(R.styleable.NumberTextView_news_number);

        mText=ta.getString(R.styleable.NumberTextView_news_text);

        mTextSize=ta.getDimensionPixelSize(R.styleable.NumberTextView_news_textSize,20);
        mMaxLine=ta.getInt(R.styleable.NumberTextView_news_textMaxLine, 1);
        ta.recycle();
        LayoutInflater.from(context).inflate(R.layout.news_item,this);
        number=findViewById(R.id.newsItem_number);
        textView=findViewById(R.id.newsItem_text);
        number.setText(mNumber);
        textView.setText(mText);
        textView.setTextSize(mTextSize);
        textView.setMaxLines(mMaxLine);

    }


    public String getName() {
        if(mText!=null){
            return mText;
        }
        return null;
    }
}
